package org.dao;

import java.util.List;

import org.model.Maestro;
import org.hibernate.SessionFactory;

public class MaestroDAO implements IMaestroDAO {

	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public Integer addMaestro(Maestro maestro) {
		return (Integer)getSessionFactory().getCurrentSession().save(maestro);
	}

	public void deleteMaestro(Maestro maestro) {
		getSessionFactory().getCurrentSession().delete(maestro);
	}


	public void updateMaestro(Maestro maestro) {
		getSessionFactory().getCurrentSession().update(maestro);
	}

	public Maestro getMaestroById(int id) {
		List list = getSessionFactory().getCurrentSession()
				.createQuery("from Maestro where id=?").setParameter(0, id).list();
		return (Maestro) list.get(0);
	}
	
	public List<Maestro> getMaestros() {
		List list = getSessionFactory().getCurrentSession()
				.createQuery("from Maestro").list();
		return list;
	}
	
}
